//
//  LiveHelper.m
//  JZMCFM
//
//  Created by lanou3g on 15/11/2.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "LiveHelper.h"
#import "LiveModel.h"

@interface LiveHelper ()

@property(nonatomic,strong) NSMutableArray *recommandMutArray;


@end

@implementation LiveHelper

static LiveHelper *shared = nil;
+(instancetype)sharedInstance{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (shared == nil) {
            shared = [[LiveHelper alloc] init];
        }
    });
    return shared;
}

#pragma mark 懒加载
-(NSMutableArray*)recommandMutArray{
    if (_recommandMutArray == nil) {
        _recommandMutArray = [NSMutableArray array];
    }
    return _recommandMutArray;
}

-(NSArray*)recommandArray{
    
    return [self.recommandMutArray copy];
}



-(void)downloadLiveDataFromNetWork:(void(^)())resultss{
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
       
        NSString *string = Livehost;
        NSURL *url = [NSURL URLWithString:string];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
           
            //解析数据
            NSDictionary *rsult1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSArray *result = rsult1[@"result"];
            for (NSDictionary *dict in result) {
                LiveModel *model = [[LiveModel alloc]init];
                [model setValuesForKeysWithDictionary:dict];
                [self.recommandMutArray addObject:model];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
               
                resultss();
                
            });
        }];
        
        
    });
}




@end
